//
//  PreviewViewController.m
//  XRSquare
//
//  Created by UaenaMo on 2018/8/15.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "PreviewViewController.h"
#import "EditViewController.h"

@interface PreviewViewController ()<UIScrollViewDelegate>
{
    UIScrollView * currentScrollView;
    
    UIImageView * imageView;
    UILabel * nkLabel;
    UILabel * titleLabel;
    UILabel * nickNameTextField;
    UILabel * sexLabel;
    UILabel * sexConntent;
    UILabel * birthLabel;
    UILabel * bitthContent;
    UILabel * shenfenLabel;
    UILabel * shenfenContent;
    
    UILabel * zhiyeLabel;
    UILabel * zhiyeConent;
    
    UILabel * workLabel;
    UILabel * workContent;
    UILabel * schoolLabel;
    UILabel * schoolContent;
    UILabel * locaitonLabel;
    UILabel * locaitonContent;
    UILabel * bioLabel;
    UILabel * bioContent;
    UILabel * phoneLabel;
    UILabel * phoneContent;
    UILabel * mailLabel;
    UILabel * mailContent;
    UILabel * qqLabel;
    UILabel * qqLabelContent;
    UILabel * wechatLabel;
    UILabel * wechatContent;
    UILabel * ecLabel;
    UILabel * ecContent;
    UILabel * connectionLabel;
    UILabel * connectionContent;
    UILabel * ecmobileLabel;
    UILabel * ecmobileContent;
    UILabel * notificationLabel;
    UISwitch * nSwitch;
    
    UIView * contentView;
    
    NSString * nickName;
    NSString * sex;
    NSString * birth;
    NSString * identity;
    NSString * work;
    NSString * school;
    NSString * locaiton;
    NSString * bio;
    NSString * phone;
    NSString * mail;
    NSString * qq;
    NSString * wechat;
    NSString * emContact;
    NSString * connection;
    NSString * emPhone;
    int notification;
    
    NSDictionary * currentData;
}
@end

@implementation PreviewViewController

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
    {

    }
    return self;
}

-(void)requestData
{
    [NetRequestCenter userInfoResult:^(BOOL success, NSDictionary *resultDic) {
        if (success)
        {
            currentData = [resultDic objectForKey:@"data"];
            [self setData:currentData];
        }
    }];
}

-(void)setData:(NSDictionary *)data
{
    NSLog(@"%@",[NSString stringWithFormat:@"%@%@",[data objectForKey:@"PicURL"],[data objectForKey:@"HeadPic"]]);
    
    [imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[data objectForKey:@"PicURL"],[data objectForKey:@"HeadPic"]]]];
    nickNameTextField.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Name"]];
    nkLabel.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Name"]];
    sexConntent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Sex"]];
    bitthContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"BirthDay"]];
    shenfenContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Identify1"]];
    zhiyeConent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Identify2"]];
    workContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Company"]];
    schoolContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"School"]];
    locaitonContent.text = [NSString stringWithFormat:@"%@ %@ %@",[data objectForKey:@"Province"],[data objectForKey:@"City"],[data objectForKey:@"District"]];
    bioContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Intro"]];
    phoneContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"MobileNumber"]];
    mailContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Email"]];
    qqLabelContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"AuthQQ"]];
    wechatContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"AuthWechat"]];
    ecContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"EmergencyContact_Name"]];
    connectionContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"EmergencyContact_RelationShip"]];
    ecmobileContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"EmergencyContact_Phone"]];
    nSwitch.on = [[NSString stringWithFormat:@"%@",[data objectForKey:@"JobPush"]]intValue];
    
    if ([nickNameTextField.text isEqualToString:@"<null>"]) {
        nickNameTextField.text = @"";
    }
    if ([nkLabel.text isEqualToString:@"<null>"]) {
        nkLabel.text = @"";
    }
    if ([sexConntent.text isEqualToString:@"<null>"]) {
        sexConntent.text = @"";
    }
    if ([bitthContent.text isEqualToString:@"<null>"]) {
        bitthContent.text = @"";
    }
    if ([shenfenContent.text isEqualToString:@"<null>"]) {
        shenfenContent.text = @"";
    }
    if ([zhiyeConent.text isEqualToString:@"<null>"]) {
        zhiyeConent.text = @"";
    }
    if ([workContent.text isEqualToString:@"<null>"]) {
        workContent.text = @"";
    }
    if ([schoolContent.text isEqualToString:@"<null>"]) {
        schoolContent.text = @"";
    }
    if ([locaitonContent.text isEqualToString:@"<null>"]) {
        locaitonContent.text = @"";
    }
    if ([bioContent.text isEqualToString:@"<null>"]) {
        bioContent.text = @"";
    }
    if ([phoneContent.text isEqualToString:@"<null>"]) {
        phoneContent.text = @"";
    }
    if ([mailContent.text isEqualToString:@"<null>"]) {
        mailContent.text = @"";
    }
    if ([qqLabelContent.text isEqualToString:@"<null>"]) {
        qqLabelContent.text = @"";
    }
    if ([wechatContent.text isEqualToString:@"<null>"]) {
        wechatContent.text = @"";
    }
    if ([ecContent.text isEqualToString:@"<null>"]) {
        ecContent.text = @"";
    }
    if ([connectionContent.text isEqualToString:@"<null>"]) {
        connectionContent.text = @"";
    }
    if ([ecmobileContent.text isEqualToString:@"<null>"]) {
        ecmobileContent.text = @"";
    }
  
}

-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];

    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.tintColor = [UIColor grayColor];
    
    [self requestData];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    
    UIBarButtonItem * editButton = [[UIBarButtonItem alloc]initWithTitle:@"编辑" style:UIBarButtonItemStylePlain target:self action:@selector(editAction)];
    self.navigationItem.rightBarButtonItem = editButton;
    
    CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
    CGRect rectNav = self.navigationController.navigationBar.frame;
    
    currentScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, rectStatus.size.height + rectNav.size.height, ScreenWidth, ScreenHeight - rectStatus.size.height - rectNav.size.height)];
    currentScrollView.delegate = self;
    [self.view addSubview:currentScrollView];
    
    imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 50, 50)];
    imageView.backgroundColor = [UIColor blackColor];
    imageView.layer.cornerRadius = 25;
    imageView.clipsToBounds = YES;
    [currentScrollView addSubview:imageView];
    
    nkLabel = [[UILabel alloc]initWithFrame:CGRectMake(70, 10, ScreenWidth - 70, 50)];
    nkLabel.font = [UIFont boldSystemFontOfSize:20];
    nkLabel.text = @"sdsd";
    [currentScrollView addSubview:nkLabel];
    
    CGFloat height = 70;
    
    {
        titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        titleLabel.font = [UIFont systemFontOfSize:15];
        titleLabel.text = @"昵称";
        [currentScrollView addSubview:titleLabel];
        
        nickNameTextField = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        nickNameTextField.textAlignment = NSTextAlignmentRight;
        [currentScrollView addSubview:nickNameTextField];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [currentScrollView addSubview:line];
        
        height += 40;
    }
    {
        sexLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        sexLabel.font = [UIFont systemFontOfSize:15];
        sexLabel.text = @"性别";
        [currentScrollView addSubview:sexLabel];
        
        sexConntent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        sexConntent.textAlignment = NSTextAlignmentRight;
        [currentScrollView addSubview:sexConntent];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [currentScrollView addSubview:line];
        
        height += 40;
    }
    {
        birthLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        birthLabel.font = [UIFont systemFontOfSize:15];
        birthLabel.text = @"出生日期";
        [currentScrollView addSubview:birthLabel];
        
        bitthContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        bitthContent.textAlignment = NSTextAlignmentRight;
        [currentScrollView addSubview:bitthContent];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [currentScrollView addSubview:line];
        
        height += 40;
    }
    {
        shenfenLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        shenfenLabel.font = [UIFont systemFontOfSize:15];
        shenfenLabel.text = @"身份";
        [currentScrollView addSubview:shenfenLabel];
        
        shenfenContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        shenfenContent.textAlignment = NSTextAlignmentRight;
        [currentScrollView addSubview:shenfenContent];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [currentScrollView addSubview:line];
        
        height += 40;
    }
    {
        zhiyeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        zhiyeLabel.font = [UIFont systemFontOfSize:15];
        zhiyeLabel.text = @"职业";
        [currentScrollView addSubview:zhiyeLabel];
        
        zhiyeConent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        zhiyeConent.textAlignment = NSTextAlignmentRight;
        [currentScrollView addSubview:zhiyeConent];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [currentScrollView addSubview:line];
    }
    
    contentView = [[UIView alloc]initWithFrame:CGRectMake(0, height + 1, ScreenWidth, 0)];
    contentView.backgroundColor  = [UIColor whiteColor];
    [currentScrollView addSubview:contentView];
    height = 0;
    {
        workLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        workLabel.font = [UIFont systemFontOfSize:15];
        workLabel.text = @"工作单位";
        [contentView addSubview:workLabel];
        
        workContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        workContent.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:workContent];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];
        
        height += 40;
    }
    {
        schoolLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        schoolLabel.font = [UIFont systemFontOfSize:15];
        schoolLabel.text = @"现就读(已毕业)学校";
        [contentView addSubview:schoolLabel];
        
        schoolContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        schoolContent.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:schoolContent];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];
        
        height += 40;
    }
    {
        locaitonLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        locaitonLabel.font = [UIFont systemFontOfSize:15];
        locaitonLabel.text = @"地址";
        [contentView addSubview:locaitonLabel];
        
        locaitonContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        locaitonContent.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:locaitonContent];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];
        
        height += 40;
    }
    {
        bioLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        bioLabel.font = [UIFont systemFontOfSize:15];
        bioLabel.text = @"个人简介";
        [contentView addSubview:bioLabel];
        
        bioContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        bioContent.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:bioContent];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];
        
        height += 40;
    }
    {
        phoneLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        phoneLabel.font = [UIFont systemFontOfSize:15];
        phoneLabel.text = @"手机";
        [contentView addSubview:phoneLabel];
        
        phoneContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        phoneContent.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:phoneContent];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];
        
        height += 40;
    }
    {
        mailLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        mailLabel.font = [UIFont systemFontOfSize:15];
        mailLabel.text = @"邮箱";
        [contentView addSubview:mailLabel];
        
        mailContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        mailContent.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:mailContent];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];
        
        height += 40;
    }
    {
        qqLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        qqLabel.font = [UIFont systemFontOfSize:15];
        qqLabel.text = @"QQ";
        [contentView addSubview:qqLabel];
        
        qqLabelContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        qqLabelContent.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:qqLabelContent];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];
        
        height += 40;
    }
    {
        wechatLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        wechatLabel.font = [UIFont systemFontOfSize:15];
        wechatLabel.text = @"微信";
        [contentView addSubview:wechatLabel];
        
        wechatContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        wechatContent.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:wechatContent];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];
        
        height += 40;
    }
    {
        ecLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        ecLabel.font = [UIFont systemFontOfSize:15];
        ecLabel.text = @"紧急联系人";
        [contentView addSubview:ecLabel];
        
        ecContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        ecContent.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:ecContent];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];
        
        height += 40;
    }
    {
        connectionLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        connectionLabel.font = [UIFont systemFontOfSize:15];
        connectionLabel.text = @"与您的关系";
        [contentView addSubview:connectionLabel];
        
        connectionContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        connectionContent.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:connectionContent];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];
        
        height += 40;
    }
    {
        ecmobileLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        ecmobileLabel.font = [UIFont systemFontOfSize:15];
        ecmobileLabel.text = @"紧急联系电话";
        [contentView addSubview:ecmobileLabel];
        
        ecmobileContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        ecmobileContent.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:ecmobileContent];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];
        
        height += 40;
    }
    {
        notificationLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        notificationLabel.font = [UIFont systemFontOfSize:15];
        notificationLabel.text = @"开启求职推送";
        [contentView addSubview:notificationLabel];
        
        nSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(ScreenWidth - 65, height + 5, ScreenWidth - 20, 20)];
        nSwitch.userInteractionEnabled = NO;
        [contentView addSubview:nSwitch];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];
        
        height += 40;
    }
    contentView.frame = CGRectMake(0, contentView.frame.origin.y, ScreenWidth, height);
    currentScrollView.contentSize = CGSizeMake(ScreenWidth, height + contentView.frame.origin.y);
}

-(void)changePosition
{
    contentView.frame = CGRectMake(0, contentView.frame.origin.y + 40, ScreenWidth, contentView.frame.size.height);
    contentView.frame = CGRectMake(0, contentView.frame.origin.y - 40, ScreenWidth, contentView.frame.size.height);
}

-(void)editAction
{
    EditViewController * edit = [[EditViewController alloc]init];
    edit.data = currentData;
    [self.navigationController pushViewController:edit animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
